package com.gupao.vip.bio;

import cn.hutool.core.convert.Convert;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Objects;

/**
 * 同步阻塞I/O的TimeClient
 */
public class TimeClient {
    public static void main(String[] args) {
        int port = Constants.DEFAULT_PORT;
        if(Objects.nonNull(args) && args.length > 0){
            port = Convert.toInt(args[0], port);
        }
        try(Socket socket = new Socket(Constants.DEFAULT_IP, port);
            BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
            ){
            out.println("QUERY TIME ORDER");
            System.out.println("Send order 2 server succeed.");
            String resp = in.readLine();
            System.out.println("Now is : "  + resp);
        }catch(Exception e){
            System.err.println("TimeClient open Socket fail" + e.getMessage());
        }
    }
}
